package com.woniu.finance.service.impl;


import com.woniu.finance.entity.Role;
import com.woniu.finance.mapper.RoleMapper;
import com.woniu.finance.service.IRoleService;
import com.woniu.util.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author o
 * @since 2023-04-25
 */
@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired(required = false)
    private RoleMapper roleMapper;

    public HttpResult<?> saveRole(Role role) {
        try {
            roleMapper.insert(role);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> removeRole(Integer id) {
        try {
            roleMapper.deleteById(id);
            return new HttpResult().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult<?> modifyRole(Role role) {
        try {

            roleMapper.updateById(role);
            return new HttpResult().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult<?> findAllRole() {
        try {
            List<Role> role = roleMapper.selectList(null);
            return new HttpResult().ok(role);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult<?> findRoleById(Integer id) {
        try {
            Role role = roleMapper.selectById(id);
            return new HttpResult<>().ok(role);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

}
